#include <iostream>
using std::cout;
using std::endl;

class Point{
public:
    Point(int x)
    : _p(new int(x))
    {
        cout << "Point(int)" << endl;
    }

#if 1
    Point & operator=(const Point & rhs){
        if(this != &rhs){//1.考虑自复制问题
            delete _p;//2.回收本对象原本申请的堆空间
            _p = new int(*(rhs._p));//3.复制
        }
        cout << "赋值运算符函数" << endl;
        return *this;
    }


    ~Point(){
        if(_p){
            delete _p;
            _p = nullptr;
        }
        cout << "~Point()" << endl;
    }
#endif
private:
    int * _p;
};

void test0(){
    Point pt(1);
    Point pt2(2);
    pt = pt2;
}

int main(void){
    test0();
    return 0;
}
